<template>
  <div class="mainsu">
    <div class="main_spac1">
      <div class="main_white padding10 paddingBottom20">
        <div class="mainor_form">
          <div class="mainor_te">
            <router-link to="/warehouse/stock/quick" class="mainor_tea"
              >快捷设置</router-link
            >
            <el-button>导入期初</el-button>
          </div>
          <el-form
            :inline="true"
            :model="form"
            class="demo-form-inline"
            ref="userListFrom"
            label-width="70px"
          >
            <el-form-item label="商品分类" prop="category_id" class="wid220">
              <el-cascader v-model="form.category_id" :options="options" :props="defaultProps"></el-cascader>
            </el-form-item>
            <el-form-item label="商品" prop="name">
              <el-input
                v-model.trim="form.name"
                placeholder="商品"
                clearable
                class="wid220"
              ></el-input>
            </el-form-item>
            <el-form-item label="状态" prop="status">
              <el-select v-model.trim="form.status" placeholder="状态" class="wid220">
                <el-option label="所有" value=""></el-option>
                <el-option
                  v-for="(statusList,index) in list.statusList"
                  :key="index"
                  :label="statusList"
                  :value="index+1"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button
                class="reset marginLeft10"
                type="primary"
                @click="$refs['userListFrom'].resetFields()"
                >重置</el-button
              >
              <el-button
                type="primary"
                @click="getArticleList"
                :loading="listLoading"
                >搜索</el-button
              >
            </el-form-item>
          </el-form>
        </div>
        <div class="main_table marginTop10" style="min-height: 550px">
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="list.list.data"
            element-loading-text="加载中"
            fit
            border
            highlight-current-row
          >
       
            <el-table-column label="商品名称" width="150" prop="goods.name" />
            <el-table-column label="SKU编码" prop="goods_spu_code" />
            <el-table-column label="单位" prop="spu_unit.title" />
            <el-table-column label="状态" prop="status">
              <template slot-scope="scope">{{
                scope.row.inventory?(scope.row.inventory.opening_status==1?'已设置':'未设置'):'未设置'
              }}</template>
            </el-table-column>
            <el-table-column label="期初库存" prop="money" >
              <template slot-scope="scope">{{ scope.row.inventory?scope.row.inventory.opening_num:'0.00' }}</template>
            </el-table-column>
            <el-table-column label="期初进价" prop="money" >
              <template slot-scope="scope">{{ scope.row.inventory?scope.row.inventory.opening_price:'0.00' }}</template>
            </el-table-column>
            <el-table-column label="期初金额" prop="money" >
              <template slot-scope="scope">{{ scope.row.inventory?scope.row.inventory.opening_money:'0.00' }}</template>
            </el-table-column>
          </el-table>
        </div>
        <div class="main_page boxdq">
          <div></div>
          <!-- 分页 -->
          <div class="main_page_r">
            <el-pagination
              :current-page="current.page"
              :page-sizes="[20, 30, 50, 100]"
              :page-size="limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalCount"
              background
              @size-change="changeLimit"
              @current-change="changePage"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { opening_index } from "@/api/warehouse/warehouseStock";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { recursion, category } from "@/utils/index";

export default {
  components: {},
  data() {
    return {
      // 分页
      current: {
        page: 1,
        per_page: 20,
      },
      limit: 20,
      totalCount: 1,
      // 列表数据
      list: {
        list: [],
      },
      listLoading: false,
      // 搜索
      form: {
        pid: "",
        category_id: [],
        status: null,
        name: "",
      },
      // 分类
      options: [],
      defaultProps: {
        children: "selfNext",
        label: "title",
        value: "id",
        checkStrictly: true,
      },
    };
  },
  created() {
    // 列表
    this.opening_index();
  },
  methods: {
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.opening_index();
    },
    // 分页
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.opening_index();
    },
    changePage(page) {
      this.current.page = page;
      this.opening_index();
    },
    // 列表
    opening_index() {
      this.listLoading = true;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, this.list_form(), this.current)
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.list_form(),
        this.current
      );
      opening_index(data).then((res) => {
        this.listLoading = false;
        if (res.errcode == 0) {
          this.options = recursion(res.data.categoryList, true);
          this.list = res.data;
          this.totalCount = res.data.list.total;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    list_form() {
      let form = JSON.parse(JSON.stringify(this.form));
      form.pid = form.category_id[0] ? form.category_id[0] : "";
      form.category_id = category(form.category_id);

      return form;
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.mainsu {
  .mainor_form form {
    width: calc(100% - 180px);
  }
}
</style>
